﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Besture.Model;

namespace Besture.Bll
{
    public class BaseDac<T> where T : BaseModel
    {
        /// <summary>
        /// 添加时加载基本数据
        /// </summary>
        /// <param name="t">数据模型</param>
        /// <returns></returns>
        public T LoadAddBaseModel(T t)
        {
            t.CreateBy = AdminUserService.AdminLoginUser == null ? 0 : AdminUserService.AdminLoginUser.ID;
            t.CreateTime = DateTime.Now;
            t.UpdateBy = AdminUserService.AdminLoginUser == null ? 0 : AdminUserService.AdminLoginUser.ID;
            t.UpdateTime = DateTime.Now;
            return t;
        }


        /// <summary>
        /// 编辑时加载基本数据
        /// </summary>
        /// <param name="t">数据模型</param>
        /// <returns></returns>
        public T LoadUpdateBaseModel(T t)
        {
            t.UpdateBy = AdminUserService.AdminLoginUser == null ? 0 : AdminUserService.AdminLoginUser.ID;
            t.UpdateTime = DateTime.Now;
            return t;
        }

        /// <summary>
        /// 加载Seo数据
        /// </summary>
        /// <param name="t"></param>
        /// <param name="seoTitle">标题</param>
        /// <param name="seoKeywords">关键字</param>
        /// <param name="seoDescription">说明</param>
        /// <returns></returns>
        public T LoadSeo(T t, string seoTitle, string seoKeywords, string seoDescription)
        {
            t.SeoTitle = seoTitle;
            t.SeoKeywords = seoKeywords;
            t.SeoDescription = seoDescription;
            return t;
        }
    }
}
